import './public-path.js'
// import React from 'react'
import ReactDOM from 'react-dom/client';
import App from './App.tsx';
import './style.less';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import { ConfigProvider } from 'antd';
import { mockRuqest } from '@/mock';
import store from '@/store';
// import routes from './router/index.tsx'
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper';

console.log('--------sub-app-react18--------');
// debugger
if (import.meta.env.MODE === 'mock') {
	mockRuqest();
}


const render = (props: any = {}) => {
	const { container } = props;
	ReactDOM.createRoot(container ? container.querySelector('#root')! : document.getElementById('root')!).render(
		// <React.StrictMode>
		<Provider store={store}>
			<BrowserRouter>
				<ConfigProvider>
					<App />
					{/* <RouterProvider router={routes} /> */}
				</ConfigProvider>
			</BrowserRouter>
		</Provider>
		// </React.StrictMode>
	);
};

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
	render({});
}

renderWithQiankun({
	async mount(props: any): Promise<any> {
		render(props);
		console.log('渲染了react子应用')
		// await props.onGlobalStateChange((state: any) => {
		// 	// console.log('子应用接收的参数', state);
		// });
		return new Promise((resolve, reject) => {
		    resolve('mount');
		})
	},
	bootstrap(): Promise<any>  {
		console.log('%c', 'color:green;', ' ChildOne bootstrap');
		return new Promise((resolve, reject) => {
			resolve('bootstrap');
		});
	},
	update() {
		console.log('%c', 'color:green;', ' ChildOne update');
		
	},
	unmount(props: any) {
		console.log('sub app vue3 unmount', props);
		// const { container } = props;
		// ReactDOM.unmountComponentAtNode(container ? container.querySelector('#root') : document.querySelector('#root'));
		//   window.location.reload()
	},
});
